package com.ljkj.cordial.chat.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ljkj.cordial.chat.R;
import com.ljkj.cordial.chat.dao.notify.GroupMemberTable;
import com.ljkj.cordial.chat.widget.PuzzleImageView;
import com.nic.view.adapter.CommonAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 纵向群成员列表
 */
public class GroupMemberVercialAdapter extends CommonAdapter<GroupMemberTable> {
    @Override
    public View getBindView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group_member_vercial, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        GroupMemberTable member = (GroupMemberTable) getItem(position);
        holder.tvName.setText(TextUtils.isEmpty(member.getGroupMemberAlias()) ? member.getGroupMemberName() : member.getGroupMemberAlias());
        if (TextUtils.isEmpty(member.getGroupMemberAvatarPath())) {
            if (!TextUtils.isEmpty(member.getGroupMemberAvatar())) {
                holder.itemImg.setFriendUrl(member.getGroupMemberAvatar(), member.getGroupMemberUserId());
            } else {
                holder.itemImg.setImageResource(R.mipmap.pic_user_avatar_default_36dp);
            }
        } else {
            holder.itemImg.setFriendPath(member.getGroupMemberAvatarPath(), member.getGroupMemberAvatar());
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.item_img)
        PuzzleImageView itemImg;
        @BindView(R.id.tv_name)
        TextView tvName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
